Repository navigation
fix(studio): an undo on a sealed preview shows in place, not after a reload - #8009
Conversation
…t takes the new kind
jrusso1020
left a comment
There was a problem hiding this comment.
APPROVE at f5b6ddd7.
-
The new request goes through the existing typed editing port. It enters
PARAM_PARSERSlike every other kind, andparseRestoreAttributesis strict:- exact key sets at every level;
timefinite and ≥ 0;- bounded scopes, elements and attributes (64 / 2,000 / 256);
- keys must be
hf:…orid:…; - attribute names match
/^[^\s"'>/=]{1,256}$/, and values are capped at 200 KB; - anything else becomes a typed error, never a throw.
-
It's all-or-nothing in the frame.
planRestoreresolves every element first and refuses on any of these:- a missing key;
- a key shared by two elements (
identityMapreturns null); - a sub-composition's rewritten root (
data-hf-inner-root); - a GSAP-parsed element while the files keep a GSAP script;
- no
__player.seek.
Only then does it set attributes and rebind.
applied: falsechanges nothing, and Studio falls back to the old reload, so a wrong or partial apply can't leave the preview half-restored. -
The isolation boundary is unchanged. The request flows Studio → sealed frame, carrying attributes Studio diffed from the saved files: the composition's own content, which a reload would load anyway. Setting attributes on existing nodes doesn't re-run a
<script>, and the frame's opaque origin and CSP still apply. The frame's only answer isapplied, so a composition that lies about it can at worst skip a reload. It can't make Studio do anything else. -
Fails-without lines hold. With main's
gsapUndoRestore.ts, two of the three sealed cases fail. Dropping the GSAP-parsed check fails the "changes nothing when…" case. The same-origin path and flag-off behaviour are unchanged. -
The
@hyperframes/inspectorbudget moves from 3,780,000 to 3,820,000 for the measured 3,819,701 bytes.
CI: 65 pass, 1 pending, 0 failing. Both commits are signed, and the title, body and commit messages carry no internal references.
Note: the body says an undo landing during a gesture in progress isn't detected on a sealed preview. That's a UX edge, not a boundary issue.
Need ✅ · Size ✅ · Reuse ✅ (the existing editing port and rebind path) · Simpler ✅
Risk: low. It's all-or-nothing, and any refusal falls back to the old reload.
— Rames
What
An undo or redo on a sealed preview (the preview on an opaque origin,
VITE_STUDIO_OPAQUE_PREVIEW_ENABLED) now shows in place, as it does on a same-origin preview. Before, Studio could not reach a sealed frame's document, so every undo fell back to a full reload of the preview, and the moved element stayed where the edit left it until that reload landed: 8.5 s later in the edit accuracy bench on a Linux box.Studio still works out the restore from the saved files alone: which identified elements changed, and each one's restored attributes. It sends that to the frame over the editing port as a new
restore-attributesrequest with the playhead time. The frame finds each element by itsdata-hf-idorid(in the document, or in every host that inlines a sub-composition), checks all of them before touching any, sets their attributes, then rebinds the timeline at the playhead (seek,__hfForceTimelineRebind, manual edits reapplied), with no script run. It answersapplied: falseand changes nothing when an element is missing, shares its key with another, is a sub-composition's rewritten root, or has been parsed by GSAP while the files keep a GSAP script; Studio then reloads the preview as before. A restore whose GSAP script itself changed still reloads.A same-origin preview takes the same path as before; nothing changes with the flag off.
The new request is part of the preview runtime, which
@hyperframes/inspectorbundles: its unpacked size measured 3,819,701 bytes in CI, so its budget inscripts/package-size-budgets.jsonmoves from 3,780,000 to 3,820,000.Why
A sealed preview keeps a composition's scripts apart from Studio's page. Undo was one of the editing paths that still read the frame directly, and the one the edit accuracy bench fails on with the preview sealed.
What I measured
On a Linux box, against this main:
--grid pr --filter '^move-idle-px-r0-(root|nested)-z100$', with the sealed default from feat(studio): Studio's preview runs sealed by default #7846 applied: undo goes from 0/2 to 1/2. The root case passes (box back within 0.5 px, file byte-identical). The nested case still reloads: its sub-composition has its own GSAP script, which takes the reload path on a same-origin preview too, and a sealed reload is slow; that is a separate change.packages/core:restoreAttributes.test.ts,editingAgent.test.ts,editingPort.test.ts, 149 tests, 3 runs, all pass.bun run typecheck(withtypecheck:runtime) clean.packages/studio:gsapUndoRestore.sealed.test.tsandgsapUndoRestore.test.ts, 47 tests, 3 runs, all pass.bun run typecheckclean.gsapUndoRestore.tsas on main, two of the three cases ingsapUndoRestore.sealed.test.tsfail (nothing is sent to the frame, the preview reloads); with the GSAP-parsed check removed fromrestoreAttributes, "changes nothing when an element is missing, shared by two, or GSAP-parsed under a script" fails.What I did NOT exercise
Before
On main with the sealed default: the edit accuracy bench's root move case, captured right after Ctrl+Z. The toast says the move was undone, but the box is still where the drag left it.
After
This branch with the sealed default, same case and moment: the box is back where it started and Studio shows "Undid: Move layer".